package io.scnb.design.store;

import io.scnb.design.store.impl.CardCommodityService;
import io.scnb.design.store.impl.CouponCommodityService;
import io.scnb.design.store.impl.GoodsCommodityService;

/**
 * 奖品工厂
 */
public class StoreFactory {
    /**
     * 通过奖品类型数值来生成奖品接口
     * @param commodityType
     * @return
     */
    public ICommodity getCommodityService(Integer commodityType) {
        if (null == commodityType) {
            return null;
        } else if (1 == commodityType) {
            return new CouponCommodityService();
        } else if (2 == commodityType) {
            return new GoodsCommodityService();
        } else if (3 == commodityType) {
            return new CardCommodityService();
        }
        throw new RuntimeException("不存在的奖品类型");
    }

    /**
     * 通过想要的奖品接口来生成奖品服务类
     * @param clazz
     * @return
     * @throws InstantiationException
     * @throws IllegalAccessException
     */
    public ICommodity getCommodityService(Class<? extends ICommodity> clazz) throws InstantiationException, IllegalAccessException {
        if (null == clazz) return null;
        return clazz.newInstance();
    }
}
